echo "部署 $appName ..."

server_host=dc-app

echo "curl -X POST  --max-time 6 --retry 3 http://$server_host/api/shell/mkdir?path=%2Fapp%2Fjava%2F$appName%2Flib "
curl -X POST  --max-time 6 --retry 3 http://$server_host/api/shell/mkdir?path=%2Fapp%2Fjava%2F$appName%2Flib

override=$(cat docker-app/split-lib/readme-split-jar.txt | grep "override: true" || true)
if [ "$override" == "" ] ; then

   echo "scp -r docker-app/split-lib/lib   root@$server_host:/app/java/$appName/"
   scp -r docker-app/split-lib/lib   root@$server_host:/app/java/$appName/

   echo " scp  docker-app/split-lib/*.jar  root@$server_host:/app/java/$appName/"
   scp  docker-app/split-lib/*.jar  root@$server_host:/app/java/$appName/

else

    echo "scp -r docker-app/lib   root@$server_host:/app/java/$appName/"
    scp -r docker-app/lib   root@$server_host:/app/java/$appName/

    echo "scp  docker-app/*.jar  root@$server_host:/app/java/$appName/"
    scp  docker-app/*.jar  root@$server_host:/app/java/$appName/
fi

echo "curl -X POST -o curl-result.txt -s -w  %{http_code} --max-time 6 --retry 3 http://$server_host/api/shell/run-$languageVersion?app=$appName"

code=$(curl -X POST -o curl-result.txt -s -w  %{http_code} --max-time 6 --retry 3 http://$server_host/api/shell/run-$languageVersion?app=$appName)


if [ "$code" == "000" ]; then
    echo "网络错误，请重试！"
    exit 3;
elif [ "$code" == "200" ]; then
    echo -e "\n"`date "+%Y-%m-%d %H:%M:%S"` '部署镜像成功!'
else
    echo -e "\n"`date "+%Y-%m-%d %H:%M:%S"` '部署镜像失败!!! 返回: $code'
    cat curl-result.txt
    exit 1
fi

echo "启动任务$appName 成功,请手动检查启动状态"